Skip to content

Fix mutable default arguments, resource leak, and redundant assignment#13185

Open
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
jashshah999:fix/mutable-defaults-and-resource-leak
Open

Fix mutable default arguments, resource leak, and redundant assignment#13185
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
jashshah999:fix/mutable-defaults-and-resource-leak

Conversation

@jashshah999
Copy link

What does this PR do?

Fixes several latent bugs across the codebase:

Mutable default arguments (shared state across calls):

  • _replace_with_gguf_linear: modules_to_not_convert=[] -> None with guard
  • _dequantize_gguf_and_restore_linear: same pattern
  • SDCascadeTimestepBlock.__init__: conds=[] -> conds=()
  • prepare_extra_kwargs (3 occurrences): exclude_kwargs=[] -> exclude_kwargs=()

Resource leak:

  • model_loading_utils.py: open(checkpoint_file, "rb").read() never closes the file handle; wrapped with a context manager

Dead code:

  • loading_utils.py: image = image self-assignment replaced with pass

- Replace mutable default lists with None/tuple in _replace_with_gguf_linear,
  _dequantize_gguf_and_restore_linear, SDCascadeTimestepBlock.__init__,
  and prepare_extra_kwargs to prevent shared state across calls
- Use context manager for open() in load_checkpoint to avoid leaking the
  file handle
- Remove redundant self-assignment (image = image) in load_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant